<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>物料单位</title>
    <link rel="stylesheet" href="../../../../public/dist/css/layui.css">
</head>

<body>

    <form class="layui-form" action="" id="example" lay-filter="example">
        <div class="select common">
            <div class="select-title"> 计量单位</div>
            <div class="select-con">

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">单位名称:</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input input-d  house" placeholder="输入单位名称" name="description">
                        </div>
                    </div>
                </div>

                <div class="select-btn" style="margin-left:30px;">
                    <div class="layui-bg-green comquery queding" id="queding">确定</div>
                    <div class="layui-bg-green comquery cancels">取消</div>
                </div>
            </div>
        </div>
    </form>
</body>
<script src="../../../../js/module/jquery-3.4.1.min.js"></script>
<script src="../../../../public/dist/layui.js" charset="utf-8"></script>
<script src="../../../../js/common/api.js"></script>

</html>


<script>
    layui.use(["table", "laydate", "form"], function() {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            obj = {},
            table = layui.table;


        //取消
        $(".cancels").click(function() {
            window.location.href = "../materialunit.html";
        });

        //编辑
        var urls = window.location.search;
        urls = urls.substring(4);
        console.log(urls)
        noAjax("coa/getUnitsList", {
            id: urls
        }, "get").done(function(resp) {

            form.val("example", resp.ipage.records[0])
            form.render('select');
            return
        }).fail(function(err) {
            console.log(err)
        });



        $("#queding").click(function() {

            if ($(".house").val() == "") {
                alerts("请选择时间")
                return
            }
            obj.description = $(".house").val()

            if (urls != "") {
                obj.id = urls;

                handleAjax("coa/updateUnits", obj, "POST").done(function(resp) {
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function() {
                        window.location.href = "../materialunit.html";
                    }, 1500)
                    return
                }).fail(function(err) {
                    console.log(err)
                });

            } else {
                handleAjax("coa/addUnits", obj, "POST").done(function(resp) {
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function() {
                        window.location.href = "../materialunit.html";
                    }, 1500)
                    return
                }).fail(function(err) {
                    console.log(err)
                });
            }
            return
        });
    });
</script>